from django.db import models

# Create your models here.
class Forum(models.Model):
	name=models.CharField('forum\'s name or title',max_length=512)
	home_url=models.CharField('forum\'s main/entry url',max_length=512)
	login_url=models.CharField(max_length=512)
	usr=models.CharField('usr name',max_length=64)
	pwd=models.CharField('passwordd',max_length=128)
	disabled=models.BooleanField(default=False)
	def __unicode__(self):
		return '<Forum|%s|%s|%s>'%(self.name,self.home_url,self.login_url)

class Sector(models.Model):
	forum=models.ForeignKey(Forum,null=True)

	name=models.CharField('sector\'s name or title',max_length=512)
	locate_id=models.CharField(max_length=64)
	url=models.CharField('sector\'s main/entry url',max_length=512)
	base_url=models.CharField('secotr\'s relative url\'s default base url',max_length=512)
	url_pattern=models.CharField('sector\'s url including page info',max_length=512)
	posts_xpath=models.CharField('sector\'s post list\'s xpath',max_length=512)
	post_title_xpath=models.CharField(max_length=512)
	post_author_xpath=models.CharField(max_length=512)
	post_reply_xpath=models.CharField(max_length=512)

class Post(models.Model):
	sector=models.ForeignKey(Sector,null=True)
##	forum=models.ForeignKey(Forum,null=True)

	locate_id=models.CharField(db_index=True,max_length=64)
	url=models.CharField('post\'s main/entry url',max_length=512)
	title=models.CharField(max_length=512)
	author=models.CharField(max_length=64)
	crt_date=models.DateTimeField(db_index=True)
	upd_date=models.DateTimeField()
	nr_reply=models.PositiveIntegerField()

class Reply(models.Model):
	post=models.ForeignKey(Post,null=False)

	locate_id=models.CharField(db_index=True,max_length=64)
##	url=models.CharField('reply\'s main/entry url',max_length=512)
	author=models.CharField(max_length=64)
	crt_date=models.DateTimeField(db_index=True)
	content=models.TextField()



#	./manage.py syncdb --database=db_postpic
class ImgFile(models.Model):
	filemd5=models.CharField('md5 of image file',max_length=64,primary_key=True)
	ext=models.CharField(max_length=4,null=False)
	size=models.PositiveIntegerField(null=False)
	width=models.PositiveIntegerField()
	height=models.PositiveIntegerField()
##	path=models.CharField(max_length=512)
##	group=models.PositiveIntegerField()
##	order_in_group=models.PositiveSmallIntegerField()

class ImgUrl(models.Model):
	'''stat: 0: init
	1: trying
	2: tried
	3: tried but hosterror
	4: notfound
	'''
	img=models.ForeignKey(ImgFile,null=True)
	url=models.CharField(max_length=255,db_index=True,unique=True)

	stat=models.PositiveSmallIntegerField(default=0)